/*
 *  $Id: Clearance.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class Clearance: SpellCard<ChainData> {
        public Clearance(): base("001_w_s_clearance") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            Target = new ChainTarget(null,
                new LandTarget(GetTargetPhrase(), true, false, IsWaterSource),
                EnchantmentTarget.OnlyDispellable);
            AddManaCost(ElementType.Water, 1);
        }

        private static bool IsWaterSource(TargetRequest request, Land land) {
            if (land.Card.Element != ElementType.Water) return false;
            return land.Summary.GetManaIncomeAll() > 0;
        }

        protected override void DoAction(TargetArgs<ChainData> args) {
            TargetArgs<Land> la;
            TargetArgs<Affect> ea;
            if (!args.Target.GetArgs(out la, out ea)) return;
            la.Target.AddAffect(new ClearanceAffect(la.Target));
            ea.Target.Dispell();
        }

        private class ClearanceAffect: SpellAffect<Clearance> {
            private AbstractObject _obj;

            public ClearanceAffect(AbstractObject obj) {
                _obj = obj;
                TimeAffect time = new TimeAffect(4);
                foreach (ElementType element in ElementType.AllElements) {
                    int income = obj.Summary.GetManaIncome(element);
                    if (income > 0) time.Add(new Affects.ManaOutcome(element, income));
                }
                Add(time);
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override Affect Clone() {
                return new ClearanceAffect(_obj);
            }
        }
    }
}
